package code.structure.manager.assist
{
	import code.main.App;
	import code.structure.module.others.ProjectAssistController;
	
	import flash.display.StageDisplayState;
	import flash.external.ExternalInterface;
	
	/**
	 * js管理器 
	 * @author Yuri
	 * 
	 */
	public class JSManager implements ISpecialManager
	{
		private var _controller:ProjectAssistController;
		public function JSManager(c:ProjectAssistController)
		{
			controller = c;
		}
		
		public function get controller():ProjectAssistController{
			return _controller;
		}
		
		public function set controller(value:ProjectAssistController):void{
			_controller = value;
			if(!ExternalInterface.available) return;
		}
		
		/**
		 * 通用调用js方法 要求js参数是数组才可以 
		 * @param jsname
		 * @param args
		 * 
		 */
		public function addJsCall(jsname:String,...args):void{
			if(!ExternalInterface.available) return;
			jsPreCheck();
			ExternalInterface.call(jsname,args);
		}
		
		/**
		 * 添加js回调 
		 * @param asname
		 * @param fun
		 * 
		 */
		public function addCallback(asname:String,fun:Function):void{
			if(!ExternalInterface.available) return;
			ExternalInterface.addCallback(asname,fun);
		}
		
		/**
		 *js调用之前的检测 
		 * 
		 */
		public function jsPreCheck():void{
			if(App.appstage.displayState !=StageDisplayState.NORMAL) App.appstage.displayState = StageDisplayState.NORMAL;
		}
	}
}